package cn.aitrox.ry.service.dwh.service.impl;

import cn.aitrox.ry.bean.RespResult;
import cn.aitrox.ry.common.service.BaseService;
import cn.aitrox.ry.enumtype.RespCodeEnum;
import cn.aitrox.ry.service.dwh.dto.DwhSeriesDto;
import cn.aitrox.ry.service.dwh.dto.out.jy.SeriesItemDto;
import cn.aitrox.ry.service.dwh.remote.JyDwhApi;
import cn.aitrox.ry.service.dwh.service.SeriesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SeriesServiceImpl extends BaseService implements SeriesService {

    @Autowired
    private JyDwhApi jyDwhApi;

    @Override
    public RespResult<List<DwhSeriesDto>> seriesQuery(List<String> seriesUids) {
        List<SeriesItemDto> seriesItemList;
        try {
            seriesItemList = jyDwhApi.seriesQuery(seriesUids);
        } catch (Exception e) {
            return RespResult.secByError(RespCodeEnum.ERROR.getCode(), e.getMessage());
        }
        List<DwhSeriesDto> list = seriesItemList.stream().map(x -> {
            DwhSeriesDto dwhSeries = new DwhSeriesDto();
            BeanUtils.copyProperties(x, dwhSeries);
            dwhSeries.setSeriesUid(x.getSeriesInstanceUID());
            dwhSeries.setStudyUid(x.getStudyInstanceUID());
            return dwhSeries;
        }).collect(Collectors.toList());
        return RespResult.ok(list);
    }
}
